package com.jy.rhin.infra.repo.notfication.topic.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jy.rhin.domain.notification.topic.entity.TopicPropertiesVO;
import com.jy.rhin.infra.repo.notfication.topic.mapper.TopicPropertiesMapper;
import com.jy.rhin.infra.repo.notfication.topic.po.TopicPropertiesPO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author dhl
 * @date 2022/7/5
 * @Description
 */
@Service
public class TopicPropertiesQueryHandler {


    @Resource
    private TopicPropertiesMapper topicPropertiesMapper;

    /**
     * 根据肢体规则获取配置列表
     *
     * @param topicExp
     * @return
     */
    public List<TopicPropertiesVO> queryTopicPropertiesList(String topicExp) {
        QueryWrapper<TopicPropertiesPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TopicPropertiesPO::getTopicExp, topicExp);
        List<TopicPropertiesPO> poList = topicPropertiesMapper.selectList(queryWrapper);
        if (!CollectionUtils.isEmpty(poList)) {
            return poList.stream().map(po -> {
                TopicPropertiesVO vo = new TopicPropertiesVO();
                BeanUtils.copyProperties(po, vo);
                return vo;
            }).collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}
